<template>
  <div class="container">
    <div class="app-container">
      <!-- 组织结构 -->
      <el-tree default-expand-all :props="defaultProps" :data="deps">
        <template #default="{ data }">
          <el-row style="width:100% ; height: 40px;" type="flex" justify="space-between" align="middle">
            <!-- 部门名称 -->
            <span>{{ data.name }}</span>

            <el-col :span="4">
              <!-- 部门负责人 -->
              <span class="manager-name">{{ data.managerName }}</span>
              <!-- 下拉列表 -->
              <el-dropdown>
                <span class="el-dropdown-link">
                  操作<i class="el-icon-arrow-down el-icon--right" />
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>添加子部门</el-dropdown-item>
                  <el-dropdown-item>编辑部门</el-dropdown-item>
                  <el-dropdown-item>删除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-col>
          </el-row>

        </template>
      </el-tree>
    </div>
  </div>
</template>
<script>
import { getDepartmentList } from '@/api/department'
import { translateListToTreeData } from '@/utils/department'

export default {
  name: 'Department',
  data() {
    return {
      deps: [
        // {
        //   name: '传智教育',
        //   managerName: '管理员',
        //   children: [
        //     { name: '总裁办', managerName: '管理员' },
        //     { name: '行政部', managerName: '文吉星' },
        //     {
        //       name: '人事部', managerName: '周天子',
        //       children: [
        //         { name: '财务核算部', managerName: '曹操' },
        //         { name: '税务管理部', managerName: '曹丕' },
        //         { name: '薪资管理部', managerName: '曹植' }
        //       ]
        //     }
        //   ]
        // }
      ],
      defaultProps: {
        children: 'children', // 设置默认的 children
        label: 'name' // 设置默认的 label
      }
    }
  },
  created() {
    this.getDepartmentList()
  },
  methods: {
    async getDepartmentList() {
      const res = await getDepartmentList()
      // console.log(res)
      this.deps = translateListToTreeData(res, 0)
    }
  }
}
</script>

<style scoped lang="scss">
.app-container {
  padding: 60px 140px;
  font-size: 14px;
}
.manager-name{
  display: inline-block;
  width: 90px;

}
</style>
